#include "../../client/rpc_client.hpp"
#include "../../common/my_tool.hpp"


void callback(const Json::Value result)
{
    ILOG("callback result: %d",result.asInt());
}

int main()
{
    // 连接注册中心
    auto client = std::make_shared<jsonrpc::client::RpcClient>(true, "127.0.0.1", 8080);
    // 1.同步测试
    Json::Value params, result;
    params["num1"] = 11;
    params["num2"] = 22;
    bool ret = client->call("Add", params, result);
    if(ret != false)
    {
        std::cout << "result: " << result.asInt() << std::endl;
    }
    // 2.异步测试
    Json::Value params2, result2;
    jsonrpc::client::RpcCaller::JsonAsyncResponse res_future;
    params2["num1"] = 33;
    params2["num2"] = 44;
    ret = client->call("Add", params2, res_future); // 调用后立即返回, 不会阻塞, 获取的时候调用future的get(没结果阻塞)
    if(ret != false)
    {
        result2 = res_future.get();
        std::cout << "result: " << result2.asInt() << std::endl;
    }
    // 3回调的测试
    Json::Value params3, result3;
    params3["num1"] = 55;
    params3["num2"] = 66;
    ret = client->call("Add", params3, callback); 
    DLOG("-----------------------")
    std::this_thread::sleep_for(std::chrono::seconds(1));
    
    return 0;
}